$(function(){
	//页面淡入效果


	//顶部时间
	function getTime(){
		var myDate = new Date();
		var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
		var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
		var myToday = myDate.getDate(); //获取当前日(1-31)
		var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
		var myHour = myDate.getHours(); //获取当前小时数(0-23)
		var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
		var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
		var week = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
		var nowTime;
		
		nowTime = myYear+'-'+fillZero(myMonth)+'-'+fillZero(myToday)+'&nbsp;&nbsp;'+week[myDay]+'&nbsp;&nbsp;'+fillZero(myHour)+':'+fillZero(myMinute)+':'+fillZero(mySecond);
		$('.topTime').html(nowTime);
	};
	function fillZero(str){
		var realNum;
		if(str<10){
			realNum	= '0'+str;
		}else{
			realNum	= str;
		}
		return realNum;
	}
	setInterval(getTime,1000);

	



	


	








	/***************2018-01-03增加js****************/

	//地图上的搜索
	$('.searchBtn').on('click',function(){
		$(this).hide();
		$('.searchInner').addClass('open');
		setTimeout(function(){
			$('.searchInner').find('form').show();
		},400);
	});

	$('.search').on('click',function(event){
		event.stopPropagation();
	});
	$('body').on('click',function(){
		$('.searchInner').find('form').hide();
		$('.searchInner').removeClass('open');
		setTimeout(function(){
			$('.searchBtn').show();
		},400);
	});

	//车辆状态滚动条样式
	$('.stateUl').niceScroll({
        cursorcolor: "#045978",//#CC0071 光标颜色
        cursoropacitymax: 0.6, //改变不透明度非常光标处于活动状态（scrollabar“可见”状态），范围从1到0
        touchbehavior: false, //使光标拖动滚动像在台式电脑触摸设备
        cursorwidth: "4px", //像素光标的宽度
        cursorborder: "0", // 	游标边框css定义
        cursorborderradius: "4px",//以像素为光标边界半径
        autohidemode: false //是否隐藏滚动条
    });


    //车辆信息工作时间表
    //模拟数据
    var carData = [
    	{
    		dateLable: "2018-01-01 星期一",
    		data: {
    			workTime: [
    				{start: "07:30",end: "13:15"},
    				{start: "14:40",end: "21:50"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-02 星期二",
    		data: {
    			workTime: [
    				{start: "03:10",end: "09:40"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-03 星期三",
    		data: {
    			workTime: [
    				{start: "06:15",end: "14:08"},
    				{start: "15:53",end: "24:00"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-04 星期四",
    		data: {
    			workTime: [
    				{start: "00:00",end: "07:32"},
    				{start: "12:20",end: "19:50"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-05 星期五",
    		data: {
    			workTime: [
    				{start: "06:15",end: "17:20"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-06 星期六",
    		data: {
    			workTime: [
    				{start: "14:40",end: "22:38"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	},
    	{
    		dateLable: "2018-01-07 星期天",
    		data: {
    			workTime: [
    				{start: "06:30",end: "12:20"},
    				{start: "14:25",end: "20:33"}
    			],
    			standard: [
    				{start: "00:00",end: "05:00"},
    				{start: "08:00",end: "12:00"},
    				{start: "14:00",end: "19:00"}
    			]
    		}
    	}
    ];

    function Schedule(){
    	var Item = $('.dataBox');
    	var Size = Item.eq(0).width();
    	var oDay = 24*60;

    	function getMin(timeStr){
    		var timeArray = timeStr.split(":");
    		var Min = parseInt(timeArray[0])*60+parseInt(timeArray[1]);
    		return Min;
    	}

    	//在时间轴上添加工作时间数据
    	Item.each(function(i,ele){
    		var ItemData = carData[i];
    		function addData(obj,dataParam){
    			for(var j=0;j<dataParam.length;j++){
	    			var pos,wid,workCeil,sDate,sStart,sEnd,sConsume;
	    			pos = getMin(dataParam[j].start)/oDay*100+'%';
	    			wid = (getMin(dataParam[j].end)-getMin(dataParam[j].start))/oDay*100+'%';
	    			sDate = ItemData.dateLable;
	    			sStart = dataParam[j].start;
	    			sEnd = dataParam[j].end;
	    			sConsume = getMin(dataParam[j].end)-getMin(dataParam[j].start);
	    			workCeil = '<span style="width: '+wid+';left: '+pos+'" sDate="'+sDate+'" sStart="'+sStart+'" sEnd="'+sEnd+'" sConsume="'+sConsume+'"></span>';
	    			obj.append(workCeil);
	    		}
    		}
    		addData($(ele).find('.workTime'),ItemData.data.workTime);
    		addData($(ele).find('.standard'),ItemData.data.standard);
    	});

    	//添加总用时与总单数
    	var Total = $('.totalItem');
    	Total.each(function(i,ele){
    		var ItemData = carData[i].data.workTime;
    		var timeUsed = 0;
    		for(var j=0;j<ItemData.length;j++){
				timeUsed+= getMin(ItemData[j].end)-getMin(ItemData[j].start);
    		}
    		var realHour = Math.floor(timeUsed/60);
    		$(ele).find('span').eq(0).html(realHour+':'+(timeUsed-realHour*60));
    		$(ele).find('span').eq(1).html(ItemData.length);
    	});
    };
    Schedule();

    //鼠标移入运单显示信息框
    $('.workTime').on('mouseenter','span',function(ev){
    	var x = ev.clientX;
    	var y = ev.clientY;
    	var sDate,sStart,sEnd,sConsume,infos,sHour,sMin;
    	sDate = $(this).attr("sDate");
		sStart = $(this).attr("sStart");
		sEnd = $(this).attr("sEnd");
		sConsume = $(this).attr("sConsume");
		sHour = Math.floor(sConsume/60);
		sMin = sConsume-sHour*60;

		infos = '<div class="workTimeInfo" style="left:'+x+'px;top:'+y+'px"><p>日期：'+sDate+'</p><p>开始时间：'+sStart+'</p><p>结束时间：'+sEnd+'</p><p>总用时：'+sHour+'小时'+sMin+'分钟</p></div>'; 
    	$('body').append(infos);
    });
    $('.workTime').on('mouseout',function(){
    	$('.workTimeInfo').remove();
    });


    //车辆信息弹出框的显示隐藏效果
    $('.infoBtn').on('click',function(){
		$('.filterbg').show();
		$('.carInfo').show();
		$('.carInfo').width('3px');
		$('.carInfo').animate({height: '76%'},400,function(){
			$('.carInfo').animate({width: '82%'},400);
		});
		setTimeout(function(){
			$('.infoBox').show();
			$('.carClose').css('display','block');
		},800);
		
	});
	$('.carClose').on('click',function(){
		$('.carClose').css('display','none');
		$('.infoBox').hide();
		
		$('.carInfo').animate({width: '3px'},400,function(){
			$('.carInfo').animate({height: 0},400);
		});
		setTimeout(function(){
			$('.filterbg').hide();
			$('.carInfo').hide();
			$('.carInfo').width(0);
		},800);
	});
});